<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        prop="detailId"
        header-align="center"
        align="center"
        label="对话详情id">
      </el-table-column>
      <el-table-column
        prop="dialId"
        header-align="center"
        align="center"
        label="对话关系id">
      </el-table-column>
      <el-table-column
        prop="userSend"
        header-align="center"
        align="center"
        label="发送方">
      </el-table-column>
      <el-table-column
        prop="content"
        header-align="center"
        align="center"
        label="发送内容">
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="创建时间">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="showUser(scope.row.userSend)">用户</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[5, 10, 20]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update> -->
  </div>
</template>

<script>
  export default {
    data () {
      return {
        dialId:0,
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
    },
    mounted () {
      // this.getDataList()
      
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        console.log("查询detail，当前页：", this.pageIndex)
        var data = {
          key:this.dataForm.key,
          page:''+this.pageIndex,
          limit:''+this.pageSize,
          sidx: 'create_time',
          order:'desc'
        }
        this.$http({
          url: this.$http.adornUrl(`/user/dialog/detail/list/${this.dialId}`),
          method: 'post',
          data: this.$http.adornData(data, false),
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        console.log('当前页：',val)
        this.pageIndex = val
        this.getDataList()
      },

      showUser(uid){
        this.$router.replace(`user-account?uid=${uid}`);
      },

      // 初始化，获取初始数据
      init(dialId){
        this.dialId = dialId
        console.log("dialogDetail 执行 init 方法")
        this.getDataList();
        /*
        this.dataList = [
          {
            detailId:1,
            dialId:this.dialId,
            content:'1说，12345',
            createTime:'2021/05/28 12:06:00',
            fromId:1,
            toId:2,
          },{
            detailId:2,
            dialId:this.dialId,
            content:'2说，上山打老虎',
            createTime:'2021/05/28 13:00:00',
            fromId:2,
            toId:1,
          }
        ]*/
      }
      
    }
  }
</script>
